Don't use drawable_get,release_context in _gdk_windowing_create_cairo_surface
authorRichard Hult <richard@imendio.com>
Tue, 20 Jan 2009 13:04:03 +0000 (14:04 +0100)
committerAlexander Larsson <alex@localhost.localdomain>
Thu, 2 Apr 2009 08:15:24 +0000 (10:15 +0200)
This fixes a mismatch in save/release gstate for the CGContext. If
this function is ever used for pixmaps, we need to add support for
that, probably will have to do so soon.

gdk/quartz/gdkdrawable-quartz.c

index 59e030dfef7b772d6021ea6aefd96f3ee502dea6..66c40922347d904c06ef9c4d0d50c7c093852968 100644 (file)
@@ -45,12 +45,21 @@ _gdk_windowing_create_cairo_surface (GdkDrawable *drawable,
                                     int          height)
 {
       CGContextRef cg_context;
+      cairo_surface_t *surface;
 
-      cg_context = gdk_quartz_drawable_get_context (drawable, TRUE);
+      /* FIXME: Can this ever be called on a non-window drawable? If so we
+       * need to check whether it's a window or pixmap and get the right
+       * kind of context, and also release it in destroy below (for bitmap
+       * context).
+       */
+
+      cg_context = [[NSGraphicsContext currentContext] graphicsPort];
       if (!cg_context)
        return NULL;
 
-      return cairo_quartz_surface_create_for_cg_context (cg_context, width, height);
+      surface = cairo_quartz_surface_create_for_cg_context (cg_context, width, height);
+
+      return surface;
 }
 
 static void
@@ -59,9 +68,6 @@ gdk_quartz_cairo_surface_destroy (void *data)
   GdkQuartzCairoSurfaceData *surface_data = data;
   GdkDrawableImplQuartz *impl = GDK_DRAWABLE_IMPL_QUARTZ (surface_data->drawable);
 
-  gdk_quartz_drawable_release_context (surface_data->drawable, 
-                                      surface_data->cg_context);
-
   impl->cairo_surface = NULL;
 
   g_free (surface_data);
@@ -204,8 +210,6 @@ gdk_quartz_draw_arc (GdkDrawable *drawable,
                                    GDK_QUARTZ_CONTEXT_FILL :
                                    GDK_QUARTZ_CONTEXT_STROKE);
 
-  CGContextSaveGState (context);
-
   start_angle = angle1 * 2.0 * G_PI / 360.0 / 64.0;
   end_angle = start_angle + angle2 * 2.0 * G_PI / 360.0 / 64.0;
 
@@ -254,8 +258,6 @@ gdk_quartz_draw_arc (GdkDrawable *drawable,
       CGContextStrokePath (context);
     }
 
-  CGContextRestoreGState (context);
-
   gdk_quartz_drawable_release_context (drawable, context);
 }